﻿using SH.Common.CommonReturn;
using SH.Multitenant.Application.IServices;
using SH.Multitenant.Infrastructure.IRepository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace SH.Multitenant.Application.Services
{
    public class BaseServices<T> : IBaseServices<T> where T : class, new()
    {
        private readonly IBaseRepository<T> _repository;

        public BaseServices(IBaseRepository<T> repository)
        {
            _repository = repository;
        }

        public ISugarQueryable<T> All => _repository.All;

        public int BatchDelete(List<T> list)
        {
            return _repository.BatchDelete(list);
        }

        public int BatchInsert(List<T> list)
        {
            return _repository.BatchInsert(list);
        }

        public async Task<int> BatchInsertAsync(List<T> list)
        {
            return await _repository.BatchInsertAsync(list);
        }

        public int BatchUpd(List<T> list)
        {
            return _repository.BatchUpd(list);
        }

        public int Delete(T t)
        {
            return _repository.Delete(t);
        }

        public List<T> GetList()
        {
            return _repository.GetList();
        }

        public async Task<List<T>> GetListAsync()
        {
            return await _repository.GetListAsync();
        }

        public List<T> GetListByCondition(Expression<Func<T, bool>> where)
        {
            return _repository.GetListByCondition(where);
        }

        public async Task<List<T>> GetListByConditionAsync(Expression<Func<T, bool>> where)
        {
            return await _repository.GetListByConditionAsync(where);
        }

        public T GetModelByCondition(Expression<Func<T, bool>> where)
        {
            return _repository.GetModelByCondition(where);
        }

        public async Task<T> GetModelByConditionAsync(Expression<Func<T, bool>> where)
        {
            return await _repository.GetModelByConditionAsync(where);
        }

        public int Insert(T t)
        {
            return _repository.Insert(t);
        }

        public async Task<int> InsertAsync(T t)
        {

            return await _repository.InsertAsync(t);
        }

        public void MultitenantBeginTran()
        {
            _repository.MultitenantBeginTran();
        }

        public void MultitenantBeginTranAsync()
        {
            _repository.MultitenantBeginTranAsync();
        }

        public void MultitenantCommit()
        {
            _repository.MultitenantCommit();
        }

        public void MultitenantCommitAsync()
        {
            _repository.MultitenantCommitAsync();
        }

        public void MultitenantRollBack()
        {
            _repository.MultitenantRollBack();
        }

        public void MultitenantRollBackAsync()
        {
            _repository.MultitenantRollBackAsync();
        }

        public ApiPaging<List<T>> PageQuery(ISugarQueryable<T> list, Expression<Func<T, bool>>? where, string? orderBy, int pageSize, int pageIndex)
        {
            return _repository.PageQuery(list, where, orderBy, pageSize, pageIndex);
        }

        public async Task<ApiPaging<List<T>>> PageQueryAsync(ISugarQueryable<T> list, Expression<Func<T, bool>>? where, string? orderBy, int pageSize, int pageIndex)
        {
            return await _repository.PageQueryAsync(list, where, orderBy, pageSize, pageIndex);
        }

        public int Upd(T t)
        {
            return _repository.Upd(t);
        }
    }
}
